﻿#region using
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using AwesomeTanks.Sources.Screens;
#endregion

namespace AwesomeTanks.Sources.GameElements.MapElements
{
    /// <summary>
    /// This is the model of a Wall in AwesomeTanks.
    /// </summary>
    public class Wall : Sprite
    {
        #region Fields

        public const float WALL_LAYER_DEPTH = 0.1f;

        public int? Health { get; set; }
        public int? MaxHealth { get; set; }

        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="Wall"/> class.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="width">The width.</param>
        /// <param name="lenght">The lenght.</param>
        /// <param name="texture">The texture.</param>
        /// <param name="sourceRectangle">The source rectangle.</param>
        public Wall(Vector2 position,int width, int lenght, Texture2D texture, Rectangle sourceRectangle)
            : this(position,width,lenght, texture, sourceRectangle, null)
        {
        }

        public Wall(Vector2 position,int width, int lenght, Texture2D texture, Rectangle sourceRectangle,int? health) : base(texture, sourceRectangle, position)
        {
            this.LayerDepth = WALL_LAYER_DEPTH;
            this.Scale = new Vector2(width, lenght);
            Health = health;
            MaxHealth = health;
        }
        #endregion

        #region Update and Draw
        /// <summary>
        /// Updates the wall at the specified game time.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public void Update(GameTime gameTime)
        {
            if (Health != null)
            {
                if (Health > 0)
                {
                    float PercentageRemainingLife = ((float)Health / (float)MaxHealth) + 0.25f;
                    this.Color = Color.White * PercentageRemainingLife;
                }
                else if (Health <= 0)
                {
                    GameplayScreen.map.DeleteWall(this);
                }
            }
        }

        /// <summary>
        /// Draws this wall with the specified sprite batch.
        /// </summary>
        /// <param name="spriteBatch">The sprite batch.</param>
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
        }
        #endregion
    }
}
